package com.giaothong.model.entity;

import org.json.JSONObject;

import com.giaothong.utils.JSONUtil;
import com.google.android.maps.GeoPoint;

public class LocationSearchEntity {
	private GeoPoint geoPoint;
	private String icon;
	private String name;
	private String types;
	private String address;

	/**
	 * setter & getter
	 */
	public void setAddress(String address) {
		this.address = address;
	}

	public void setGeoPoint(GeoPoint geoPoint) {
		this.geoPoint = geoPoint;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setTypes(String types) {
		this.types = types;
	}

	public String getAddress() {
		return address;
	}

	public GeoPoint getGeoPoint() {
		return geoPoint;
	}

	public String getIcon() {
		return icon;
	}

	public String getName() {
		return name;
	}

	public String getTypes() {
		return types;
	}

	public LocationSearchEntity() {
		setDefautValue();
	}

	public LocationSearchEntity(JSONObject jsonObject) {
		setDefautValue();
		if (jsonObject == null)
			return;
		this.address = JSONUtil.stringTryGetValue(jsonObject, "vicinity");
		if (this.address.equals("-"))
			this.address = JSONUtil.stringTryGetValue(jsonObject, "formatted_address");
		this.icon = JSONUtil.stringTryGetValue(jsonObject, "icon");
		this.name = JSONUtil.stringTryGetValue(jsonObject, "name");
		this.types = JSONUtil.stringTryGetValue(jsonObject, "types");

		this.geoPoint = JSONUtil.geoPointTryGetValue(JSONUtil.jsonObjectTryGetValue(jsonObject, "geometry"), "location");
	}

	private void setDefautValue() {
		this.address = "";
		this.geoPoint = new GeoPoint(0, 0);
		this.icon = "";
		this.name = "";
		this.types = "";
	}

}
